package com.gxa.modules.sys.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.AssertUtils;
import com.gxa.common.utils.PageUtils;
import com.gxa.modules.community.util.Result;
import com.gxa.modules.sys.entity.*;
import com.gxa.modules.sys.service.HouseLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "住户标签接口")
@RestController
@Slf4j
public class HouseLabelController {
    @Autowired
    private HouseLabelService houseLabelService;

    @ApiOperation(value="住户标签管理(查询条件标签名称)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "labelName",value = "标签名称",dataType ="String"),
    })
    @GetMapping("/houseLabel/list")
    public Result<List<HouseLabel>> houseLabelList(@RequestParam Map<String,Object> params){
        log.info("----params-----{}----",params);
        AssertUtils.isBlank(String.valueOf(params), "字符串不为能空");

        Result<List<HouseLabel>> r = Result.success();
        try {
            PageInfo<HouseLabel> pageInfo = houseLabelService.queryHouseLabel(params);
            r = Result.success(pageInfo.getList(),pageInfo.getTotal());
        }catch (Exception e){
            e.printStackTrace();
            r = Result.failed();
        }
        return r;
    }

    @ApiOperation(value="住户标签 添加")
    @PostMapping("/houseLabel/add")
    public com.gxa.common.utils.Result<PageUtils> houseLabelAdd(@RequestBody HouseLabelAdd houseLabelAdd) {
        houseLabelAdd.setState("1");
        log.info("----houseLabelAdd-----{}----", houseLabelAdd);
        AssertUtils.isBlank(String.valueOf(houseLabelAdd), "字符串不为能空");
        this.houseLabelService.addHouseLabel(houseLabelAdd);
        return new com.gxa.common.utils.Result<PageUtils>().ok();
    }

    @ApiOperation(value="住户标签 修改")
    @PutMapping("/houseLabel/update")
    public com.gxa.common.utils.Result<PageUtils> houseLabelUpdate(@RequestBody HouseLabelUpdate houseLabelUpdate) {
        log.info("----houseLabelUpdate-----{}----", houseLabelUpdate);
        AssertUtils.isBlank(String.valueOf(houseLabelUpdate), "字符串不为能空");
        this.houseLabelService.updateHouseLabel(houseLabelUpdate);
        return new com.gxa.common.utils.Result<PageUtils>().ok();
    }

    @ApiOperation(value="住户标签 删除")
    @DeleteMapping("/houseLabel/delete")
    public com.gxa.common.utils.Result<PageUtils> houseLabelDalete(@RequestBody Integer[] ids) {
        log.info("----ids-----{}----", ids);
        AssertUtils.isBlank(String.valueOf(ids), "字符串不为能空");
        for (Integer id:ids){
            System.out.println(id);
            this.houseLabelService.deleteHouseLabel(id);
        }
        return new com.gxa.common.utils.Result<PageUtils>().ok();
    }

}
